package com.itheima.youdianda.controller;

import com.itheima.youdianda.common.Result;
import com.itheima.youdianda.domain.YddUser;
import com.itheima.youdianda.service.YddUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ydd_user")
public class YddUserController {

    @Autowired
    private YddUserService yddUserService;

    /**
     * 用户管理分页查询
     * @param page
     * @param limit
     * @param sex
     * @param username
     * @param mobile
     * @return
     */
    @GetMapping("list")
    public Result findYddUser(@RequestParam (value = "page",required = false,defaultValue = "1") Integer page,
                              @RequestParam (value = "limit",required = false,defaultValue = "10") Integer limit,
                              Integer sex,String username,String mobile){
        return yddUserService.findYddUser(page,limit,sex,username,mobile);
    }

    /**
     * 添加用户
     * @param yddUser
     * @return
     */
    @PostMapping("add")
    public Result saveYddUser(@RequestBody YddUser yddUser){
        return yddUserService.saveYddUser(yddUser);
    }


    /**
     * 删除用户
     * @param id
     * @return
     */
    @GetMapping("del")
    public Result delYddUser(Integer id){
       yddUserService.removeById(id);
       return Result.ok(null);
    }

    /**
     * 修改回显
     * @param id
     * @return
     */
    @GetMapping("rowInfo")
    public Result findById(Integer id){
        YddUser yddUser = yddUserService.getById(id);
        return Result.ok(yddUser);
    }

    /**
     * 修改操作
     * @param yddUser
     * @return
     */
    @PostMapping("update")
    public Result update(@RequestBody YddUser yddUser){
        return yddUserService.updateYddUser(yddUser);
    }
}
